/**
** @DESCRIPTION:
**
** @FILE: main.c
**
** @CREATED: 2011-7-6, by chenggang
**
** @{
**/
#include <wsnos.h>

#include <driver.h>

#include <task.h>
#include <data_type_def.h>

static void idle_task(void *e)
{
	SET_POWER_MODE(1);
}

static void task(void *param)
{	
	osel_init();
	
	task_cb *task1 = osel_task_create(&tick_task_a, TICK_TASK_A_PRIO);
    task_cb *task2 = osel_task_create(&tick_task_b, TICK_TASK_B_PRIO);

    osel_subscribe(task1, OSEL_TICK_A_SIG);
    osel_subscribe(task1, OSEL_B2A_SIG);
    osel_subscribe(task2, OSEL_TICK_B_SIG);
    osel_subscribe(task2, OSEL_A2B_SIG);
    osel_subscribe(task2, OSEL_TICK_A_SIG);

    task_a_mode_init();

	osel_idle_sethook(&idle_task);

	osel_post(OSEL_TICK_A_SIG, OSEL_NULL, OSEL_EPOOL_PRIO_LOW);
	osel_run();
}

hal_timer_t *htimer_id;
static uint8_t test_flag = 0;
static void test_cb(void *p)
{
	test_flag = 0;
}

static void htimer_test(void *e)
{
    set_timer_t t0;
	hal_timer_get_now(&t0);
	hal_timer_t t1;
	t1.stimer.w = t0.w + 10000;
	htimer_id = hal_timer_at(&(t1.stimer), &test_cb, NULL);
}


void main(void)
{
//  board_init();
	SET_MAIN_CLOCK_SOURCE(CRYSTAL);
    SET_LOW_CLOCK(CRYSTAL);
	//SET_LOW_CLOCK(OSC32K_RC);
    hal_timer_init();
	
    //task(OSEL_NULL);
	while(1)
	{	
		if(test_flag == 0)
		{
			test_flag = 1;
			htimer_test(OSEL_NULL);    
			//SET_POWER_MODE(1);
		}
		
	}
}

/**@}**/


